import React, { FC, useContext, useState } from 'react';
import { View, Text } from '@tarojs/components';
import { styled } from 'linaria/react';
import { useClassName } from '@/utils/index';
import { ImageUploader } from 'antd-mobile';
import { useChangeAvatar } from './useChangeAvatar';
import Header from '../_components/Header/Header';

export interface IProps extends ICompProps {}
ChangeAvatar.defaultProps = {} as Partial<IProps>;
function ChangeAvatar(props: IProps) {
    const { className, style } = props;
    const localClassName = useClassName('ChangeAvatar', className);

    const { fileList, isActiveConfirmBtn, onDelete, setFileList, cancel, confirm, upload, beforeUpload } =
        useChangeAvatar();
    return (
        <RootView className={localClassName} style={style}>
            <Header cancel={cancel} confirm={confirm} isActiveConfirmBtn={isActiveConfirmBtn}></Header>
            <View className="ImageUploader_wrap">
                <ImageUploader
                    imageFit="fill"
                    style={{ '--cell-size': '50vw' }}
                    value={fileList}
                    maxCount={1}
                    onChange={setFileList}
                    upload={upload}
                    onDelete={onDelete}
                    beforeUpload={beforeUpload}></ImageUploader>
            </View>
        </RootView>
    );
}
export default React.memo(ChangeAvatar as FC<IProps>);
const RootView = styled(View)`
    &.ChangeAvatar {
        padding: 40px;
        .ImageUploader_wrap {
            display: flex;
            justify-content: center;
        }
        .adm-image-uploader-cell-delete {
            width: 50px;
            height: 50px;
            font-size: 40px;
        }
    }
`;
